package sicnu.cs.aps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import sicnu.cs.aps.domain.entity.StudentInfo;
import sicnu.cs.aps.domain.entity.TeacherInfo;
import sicnu.cs.aps.domain.vo.SimpleUserDetailInfoVo;
import sicnu.cs.aps.mapper.TeacherInfoMapper;
import sicnu.cs.aps.service.ITeacherInfoService;

import java.util.ArrayList;
import java.util.List;

/**
 * description 老师信息service
 *
 * @author chenhetao
 * @version 1.0
 * @className TeacherInfoServiceImpl
 * @packageName sicnu.cs.aps.service.impl
 * @date 2022/6/2 16:22
 */
@AllArgsConstructor
@Service
public class TeacherInfoServiceImpl extends ServiceImpl<TeacherInfoMapper,TeacherInfo> implements ITeacherInfoService {
    private final TeacherInfoMapper teacherInfoMapper;
    /**
     * 通过模糊条件查询老师信息(工号和姓名)
     *
     * @param condition 工号或姓名前缀
     * @return 返回工号姓名的列表
     */
    @Override
    public List<SimpleUserDetailInfoVo> listTeacherByCondition(String condition) {
        List<TeacherInfo> teacherInfos ;
        List<SimpleUserDetailInfoVo> list = new ArrayList<>();

        try {
            Long sid = Long.valueOf(condition);
            //查询工号
            teacherInfos = teacherInfoMapper.selectStByPrefixSid(condition);
        } catch (NumberFormatException e) {
            //查询姓名
            teacherInfos = teacherInfoMapper.selectStByPrefixName(condition);
        }
        teacherInfos.forEach(teacherInfo -> list.add(SimpleUserDetailInfoVo.builder().value(teacherInfo.getName()).label(teacherInfo.getUserId()).build()));
        System.out.println(1);
        return list;
    }
}
